## Compute Fresnel integrals through Gauss-Legendre quadrature
f1 <- function(t) sin(0.5 * pi * t^2)
f2 <- function(t) cos(0.5 * pi * t^2)
for (x in seq(0.5, 2.5, by = 0.5)) {
cgl <- gaussLegendre(51, 0, x)
fs <- sum(cgl$w * f1(cgl$x))
fc <- sum(cgl$w * f2(cgl$x))
cat(formatC(c(x, fresnelS(x), fs, fresnelC(x), fc),
digits = 8, width = 12, flag = "----"), "")
}
xs <- seq(0, 7.5, by = 0.025)
ys <- fresnelS(xs)
yc <- fresnelC(xs)
## Function plot of the Fresnel integrals
plot(xs, ys, type = "l", col = "darkgreen",
xlim = c(0, 8), ylim = c(0, 1),
xlab = "", ylab = "", main = "Fresnel Integrals")
lines(xs, yc, col = "blue")
legend(6.25, 0.95, c("S(x)", "C(x)"), col = c("darkgreen", "blue"), lty = 1)
grid()
## The Cornu (or Euler) spiral
plot(c(-1, 1), c(-1, 1), type = "n",
xlab = "", ylab = "", main = "Cornu Spiral")
lines(ys, yc, col = "red")
lines(-ys, -yc, col = "red")
grid()
Run the code above in your browser using DataLab